﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using nwrole.lib;

namespace nwrole.Supervisor {
    public partial class SupervisorService : ServiceBase {
        
        private static int SupervisorPort = 8094;

        private SupervisorHost supervisorHost;

        private ConsoleLogWriter consoleLogWriter = new ConsoleLogWriter();

        public SupervisorService() {
            InitializeComponent();

            Console.SetOut(consoleLogWriter);
        }

        protected override void OnStart(string[] args) {
            EventLogger.LogInformation("SupervisorService.OnStart", "SupervisorService starting");

            supervisorHost = new SupervisorHost(new nwrole.lib.StandardServiceProvider(), "nwrole.lib.StandardPluginProvider", SupervisorPort);

            supervisorHost.Start();
            
            EventLogger.LogInformation("SupervisorService.OnStart", "SupervisorService started");
        }

        protected override void OnStop() {
            EventLogger.LogInformation("SupervisorService.OnStop", "SupervisorService stopping");

            supervisorHost.Stop();

            EventLogger.LogInformation("SupervisorService.OnStop", "SupervisorService stopped");
        }
    }
}
